package com.firesrc.util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import jodd.datetime.JDateTime;
import jodd.typeconverter.Convert;

import com.firesrc.bean.Keyword;

public class RstToListUitl {

  public static List<Keyword> getKeywordListFromRst(ResultSet rst) {
    List<Keyword> list = new ArrayList<Keyword>();
    Keyword keyword = null;
    try {
      while (rst.next()) {
        keyword = new Keyword();
        keyword.setId(rst.getString("ID"));
        keyword.setName(rst.getString("NAME"));
        keyword.setTopic(rst.getString("TOPIC"));
        keyword.setComment(rst.getString("COMMENT"));
        keyword.setState(rst.getString("STATE"));
        keyword.setFlag(rst.getString("FLAG").toCharArray()[0]);
        keyword.setSearchcount(rst.getInt("SEARCHCOUNT"));
        String date = rst.getString("CREATEDATE");
        if (date != null) {
          JDateTime jdata = new JDateTime(date);
          keyword.setCreatedate(Convert.toDate(jdata));
        }
        list.add(keyword);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return list;
  }

}
